package com.sneaker.shower.config;


import com.sneaker.shower.socket.Channel;
import com.sneaker.shower.socket.feature.Config;
import com.sneaker.shower.socket.repository.ChannelRepository;
import com.sneaker.shower.socket.repository.GroupRepository;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <h1>RepositoryConfig</h1>
 * <pre>
 * @Description
 * </pre>
 *
 * @Author lopo
 * @Date 2018/10/19
 */
@Configuration
public class RepositoryConfig{

    @Bean("channelRepository")
    @ConditionalOnMissingBean(
            name = "channelRepository"
    )
    public ChannelRepository channelRepository(@Qualifier("groupRepository") GroupRepository<Channel> groupRepository){
        ChannelRepository channelRepository =  new ChannelRepository(groupRepository);
        Config.repository(channelRepository,groupRepository);
        return channelRepository;
    }

    @Bean("groupRepository")
    @ConditionalOnMissingBean(
            name = "groupRepository"
    )
    public GroupRepository<Channel> groupRepository(){
        return new GroupRepository<>();
    }
}
